home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Warrior’s Progress / source code / Source / Libraries / Memory / MasterPointer.cp < prev    next >
Encoding:
Text File  |  1997-06-28  |  1.6 KB  |  78 lines  |  [TEXT/CWIE]

  1. // MasterPointer.cp
  2.  
  3. #ifndef MasterPointer_h
  4. #include "MasterPointer.h"
  5. #endif
  6. #ifndef MemoryFullError_h
  7. #include "MemoryFullError.h"
  8. #endif
  9.  
  10. void MasterPointer::ThrowAllocationError( OSErr error, void *pointer )
  11.   {
  12.     if ( error == memFullErr )
  13.         throw MemoryFullError();
  14.     
  15.     if ( error != noErr )
  16.         throw MemoryError( error );
  17.     
  18.     if ( pointer == 0 )
  19.         throw MemoryFullError();
  20.   }
  21.  
  22. void *MasterPointer::operator new( uint32 pointerSize )
  23.   {
  24.     Assert( pointerSize == sizeof( void * ) );
  25.     void *result = NewEmptyHandle();
  26.     
  27.     ThrowAllocationError( MemError(), result );
  28.     
  29.     return result;
  30.   }
  31.  
  32. void *MasterPointer::operator new( uint32 pointerSize, uint32 blockSize )
  33.   {
  34.     Assert( pointerSize == sizeof( void * ) );
  35.     void *result =  NewHandle( blockSize );
  36.     
  37.     ThrowAllocationError( MemError(), result );
  38.     
  39.     return result;
  40.   }
  41.  
  42. void *MasterPointer::operator new( uint32 pointerSize, SystemHeap )
  43.   {
  44.     Assert( pointerSize == sizeof( void * ) );
  45.     void *result = NewEmptyHandleSys();
  46.     
  47.     ThrowAllocationError( MemError(), result );
  48.     
  49.     return result;
  50.   }
  51.  
  52. void *MasterPointer::operator new( uint32 pointerSize, uint32 blockSize, SystemHeap )
  53.   {
  54.     Assert( pointerSize == sizeof( void * ) );
  55.     void *result =  NewHandleSys( blockSize );
  56.     
  57.     ThrowAllocationError( MemError(), result );
  58.     
  59.     return result;
  60.   }
  61.  
  62. void *MasterPointer::operator new( uint32 pointerSize, uint32 blockSize, Temporary )
  63.   {
  64.     Assert( pointerSize == sizeof( void * ) );
  65.     OSErr error;
  66.     void *result = TempNewHandle( blockSize, &error );
  67.     
  68.     ThrowAllocationError( error, result );
  69.     
  70.     return result;
  71.   }
  72.  
  73. void MasterPointer::operator delete( void *handle )
  74.   {
  75.     DisposeHandle( static_cast<::Handle>( handle ) );
  76.   }
  77.  
  78.